﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Core.Utility.Extendsions.Validation
{
    /// <summary>
    /// 有效结果信息
    /// </summary>
    public class ValidationResultInfo : INotifyPropertyChanged
    {
        /// <summary>
        /// 默认构造
        /// </summary>
        public ValidationResultInfo()
        {
            _isValid = false;
        }

        /// <summary>
        /// 属性改变事件
        /// </summary>
        public event PropertyChangedEventHandler? PropertyChanged;

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ValidationResultInfo(bool isValid)
        {   
            _isValid = isValid;
        }

        /// <summary>
        /// 实现通知更新
        /// </summary>
        /// <param name="propertyName"></param>
        public void OnPropertyChanged([CallerMemberName] string? propertyName = "")
        {
            if (!string.IsNullOrEmpty(propertyName))
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #region 是否有效

        /// <summary>
        /// 是否有效
        /// </summary>
        private bool _isValid = false;

        /// <summary>
        /// 是否有效
        /// </summary>
        public bool IsValid
        {
            get { return _isValid; }
            set 
            { 
                _isValid = value;
                OnPropertyChanged();
            }
        }

        #endregion 是否有效 

        #region 错误信息
        /// <summary>
        /// 错误信息
        /// </summary>
        private string? _errorInfo;

        /// <summary>
        /// 错误信息
        /// </summary>
        public string? ErrorInfo
        {
            get { return _errorInfo; }
            set 
            { 
                _errorInfo = value;
                OnPropertyChanged();
            }
        }
        #endregion 错误信息 
    }
}
